#pragma once
#include "Common.h"
#include "ObjectPool.h"
#include "SpanList.hpp"
class PageCache
{
private:
	SpanList _spanLists[NPAGES];

	static PageCache _sInst;

	PageCache(){}

	PageCache(const PageCache&) = delete;

	std::unordered_map<PAGE_ID, Span*> _idSpanMap;

	ObjectPool<Span> _spanPool;

public:
	std::mutex _pageMutex;

	void ReleaseSpanToPageCache(Span* span);

	Span* MapObjectToSpan(void* obj);

	ObjectPool<Span>& GetSpanObjectPool()
	{
		return _spanPool;
	}

	static PageCache* GetInstance()
	{
		return &_sInst;
	}
	Span* NewSpan(size_t k);
};